<template>
  <div class="login-main">
    <Box class="login-box">
      <p>登&nbsp录</p>
      <InputLine v-model="loginForm.username" class="inputline" placeholder="username"/>
      <InputLine v-model="loginForm.password" class="inputline" type="password" placeholder="password"/>
      <div class="bottom">
        <Button @click="Login">登录</Button>
        <Button @click="Register">注册</Button>
      </div>
    </Box>
  </div>
</template>

<script>
import Auth from '@/utils/Auth'
export default {
  data () {
    return {
      loginForm: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    Login () {
      this.$http.post('/api/user/login', this.loginForm,
      res => {
        Auth.setAccessToken(res.data.token)
        Auth.setUser(res.data.user)
        this.$router.push({ name: 'Index' })
      })
    },
    Register () {
      this.$router.push({ name: 'Register' })
    }
  }
}
</script>


<style lang="less" scoped>
  .login-box{
    width: 400px;
    margin: 250px auto 0;
    font-size: 30px;
    color: #fff;
    text-align: center;
    p{
      margin: 15px 0;
    }
    .inputline{
      margin-top: 15px
    }
    .bottom{
      width: 200px;
      margin: 20px auto;
      display: flex;
      justify-content: space-between;
    }
  }
</style>

